package cn.torna.tornaexample.common;

import io.swagger.v3.oas.annotations.media.Schema;

public class Result<T> {
    @Schema(description = "状态码，0：成功", example = "0")
    private Integer code = 0;

    @Schema(description = "数据")
    private T data;

    @Schema(description = "消息")
    private String msg;

    public Result(T data) {
        this.data = data;
    }

    public static <E> Result<E> ok(E obj) {
        return new Result<>(obj);
    }

    public static Result<?> error(String msg) {
        Result<Object> result = new Result<>(null);
        result.setCode(1);
        result.setMsg(msg);
        return result;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}
